package ControlLayer;

import static org.junit.Assert.*;

import org.junit.Test;

import ModelLayer.Product;
import ModelLayer.Enums.CustomerType;
import ModelLayer.Enums.PaymentType;
import TUILayer.MainUI;

public class SaleJunit {
	
	/**
	 * Tests create sale flow
	 * @throws Exception
	 */
	@Test
	public void createSale() throws Exception {
		int i = 5;
		int e = 1;

		ProductCtr pctr = new ProductCtr();
		Product p = pctr.findProduct("varenummer1");
		
		SaleCtr sc = new SaleCtr();
		sc.startSale();
		
		int oldSize = sc.getSizeOfPartOrders();
		sc.enterProduct("varenummer1", e);
		sc.enterProduct("varenummer1", i);
		int newSize = sc.getSizeOfPartOrders();
		
		if (oldSize == newSize) {
			throw new Exception("Products not found");
		}
		
		sc.assignCustomer("53616797", CustomerType.PRIVATE);
		
		if (!sc.customerExists()) {
			throw new Exception("Customer is not found in sale");
		}
		
		String customerName = sc.getCustomerName();
		assertEquals("Tobias", customerName);
		
		sc.setDiscount();
		sc.acceptPayment(PaymentType.Creditcard, p.getPrice() * (i + e));
		sc.finishSale();
		
		// remove sale again
		sc.removeCurrentSale();
	}
}
